找传奇、传世资源到传世资源站!

C# 多线程下载文件(http,亲测通过)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

多线程下载, 下载的测试网址可以输入这个 http://www.youpaopao.com/apkdown/youpaopao.apk下载后可以在 默认D盘中找到下载的文件C# 多线程下载文件(http,亲测通过) C#语言基础-第1张using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Threading;namespace DownLoadHttp3{ public partial class Form1 : Form { public Form1() { Control.CheckForIllegalCrossThreadCalls = false; InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.txtSrcAddress.Text = @"http://www.100-try.com/soft/v.rar"; this.txtTarAddress.Text = @"D:"; } private void btnDown_Click(object sender, EventArgs e) { //加到一个线程里面是为了防止假死 Thread th = new Thread(new ThreadStart(this.DownLoad)); th.Start(); } private void DownLoad() { this.numUpDown.Enabled = false; this.btnDown.Enabled = false; //url string url = this.txtSrcAddress.Text.Trim(); //保存的路径 string dir = this.txtTarAddress.Text.Trim(); //线程数 int threadNums = (int)this.numUpDown.Value; ThreadDownload down = new ThreadDownload(threadNums, url, dir); down.StartDownLoad(); //进度条 this.statusBar_process.Maximum = (int)down.FileSize; while (!down.IsComplete) { this.statusBar_process.Value = down.DownFileSize; } if (down.IsComplete) { this.numUpDown.Enabled = true; this.btnDown.Enabled = true; } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复